var form;
var $;
var table;
var layer;
var upload;
var node;
var user = JSON.parse(localStorage.getItem("user"));
var userId = user.userId;
layui.use(['form','jquery','table','layer','upload'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;
    layer = layui.layer;
    upload = layui.upload;

    //展示树节点
    getJsActicleCategroy();
})

function getJsActicleCategroy() {
    $.ajax({
        url:'/microcircle/getJsActicleCategroy',
        type: "post",
        dataType:'json',
        data: {},
        success:function (data) {
            showZtree(data.data);
        }
    });
}

function showZtree(data) {
    var setting = {
        data:{
            simpleData: {
                enable: true,  //true 、 false 分别表示 使用 、 不使用 简单数据模式
                idKey: "acticleCategroyId",  //节点数据中保存唯一标识的属性名称
                pIdKey: "parentId",    //节点数据中保存其父节点唯一标识的属性名称
                rootPId: -1  //用于修正根节点父节点数据，即 pIdKey 指定的属性值
            },
            key: {
                name: "artcleCategroyName"  //zTree 节点数据保存节点名称的属性名称  默认值："name"
            }
        },
        check: {
            enable: true,
            chkStyle: "radio",
            radioType: "all"
        },
        view:{
            showLine: true,
            showIcon:false,
        },
        callback:{
            onCheck: choose, //点击选择分类
        }
    };

    function choose(event,treeId,treeNode){
        console.log(treeNode);
        //parent.$("input[name=acticleCategroyId]").val(treeNode.acticleCategroyId);
        $("input[name=acticleCategroyId]").val(treeNode.acticleCategroyId);
        $("input[name=artcleCategroyName]").val(treeNode.artcleCategroyName);
    }

    //初始化ztree
    zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, data );
    zTreeObj.expandAll(true);//展开全部节点
}

//确定
function sub() {
    var acticleCategroyId = $("input[name=acticleCategroyId]").val();
    var artcleCategroyName = $("input[name=artcleCategroyName]").val();
    parent.$("input[name=acticleCategroyId]").val(acticleCategroyId);
    parent.$("input[name=artcleCategroyName]").val(artcleCategroyName);
    console.log(parent.$("input[name=acticleCategroyId]").val());
    console.log(parent.$("input[name=artcleCategroyName]").val());
    var layer = parent.layer;
    layer.close(layer.index);
}

//取消
function cancel() {
    var layer = parent.layer;
    layer.close(layer.index);
}